<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
 <head>
  <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" charset="UTF-8" >
  <title> 计算器 </title>
  <script type='text/javascript'>
			window.onload = function(){
			var input = document.getElementById('input');
			var table = document.getElementById('table');
			var time = document.getElementById('time');
			var zero = document.getElementById('zero');
			var del = document.getElementById('del');
			time.innerHTML=new Date().toLocaleString();
			setInterval("document.getElementById('time').innerHTML=new Date().toLocaleString();",1000);
			var k = 1;
			var one = '';
			var tou = '';
			var arr =['7','8','9','/','4','5','6','*','1','2','3','-','.','0','+','='];
			var arr1 = [];
			zero.onclick = function(){
				window.location.reload();
			}
			del.onclick = function(){
				arr1.pop();
				input.value = arr1.join('');
				console.log(arr1);
			}
			for(var but=0;but<arr.length;but++){
				if(but%4==0){
				var row = table.insertRow(-1);
					}
					var cell = row.insertCell(-1);
					var wb = document.createElement('button');
					wb.className = 't';
					wb.innerHTML = arr[but];
					
					wb.onclick = function(){
						if(this.innerHTML=='='){
							var jie = eval(one+input.value);
							arr1 = [];
							if (jie=='Infinity') {
								alert('tips:除数不能为0');
							} else{
								input.value = jie;
								one = '';
								tou = input.value;
							}
							if(this.innerHTML=='.'){
								window.location.reload();
							}
						} else {
								if (input.value=='0') {
									if(this.innerHTML=='.'){
										input.value = input.value+this.innerHTML;
									} else {
										document.getElementById('input').value='';
										input.value = input.value+this.innerHTML;
									}
									if (this.innerHTML=='+'||this.innerHTML=='-'||this.innerHTML=='*'||this.innerHTML=='/') {
										document.getElementById('input').value='0';
									}
								} else{
									if (this.innerHTML=='+'||this.innerHTML=='-'||this.innerHTML=='*'||this.innerHTML=='/') {
										input.value = input.value+this.innerHTML;
										one = input.value;
										document.getElementById('input').value='';
										arr1 = [];
									} else{
										if (tou=='') {
											input.value = input.value+this.innerHTML;
										} else{
											tou = '';
											document.getElementById('input').value='';
											input.value = input.value+this.innerHTML;
										}
									}
								}
							}
						if (this.innerHTML=='+'||this.innerHTML=='-'||this.innerHTML=='*'||this.innerHTML=='/'||this.innerHTML=='='){
							
						} else {
							arr1.push(this.innerHTML);
							console.log(arr1);
						}
					}
					cell.appendChild(wb);
				}
			}
		</script>
 </head>
	<style type='text/css'>
		#div{width:300px; height:448px; border:double; margin:100px auto;}
		#input{width:296px; height:60px; font-size:40px; text-align:right;}
		#time{width:144px; height:70px; margin:1px; font-size:18px;}
		#zero{width:68px; height:70px; margin:1px; font-size:30px;}
		#del{width:68px; height:70px; margin:1px; font-size:30px;}
		.t{width:68px; height:70px; margin:1px; font-size:30px;}
	</style>
 <body>
  <div id='div'>
	<input id='input' readonly='readonly' value='0' />
	
	<table id='table'>
		<tr>
			<td colspan="2"><button id="time"></button></td>
			<td><button id="zero">AC</button></td>
			<td><button id="del">⇦</button></td>
		</tr>
	</table>
  </div>
 </body>
</html>
